﻿@{
    Bundle("jquery_rateit");
    Layout = "../Shared/_Default.cshtml";
    var t_supplier = (Model.Translations as IEnumerable<dynamic>)
        .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
            JDM.Int32(Svc.Localization.Language.EntityID));
    ViewBag.PageTitle = T(Res.Name("Title"), t_supplier != null ? JDM.String(t_supplier.Name) : String.Empty);
    ViewBag.PageHistory = true;
}

@section Toolbar
{
    @if(JDM.HasFlags(Model.Flags, "CommentAllowed") &&
        (Svc.IsAuthenticated || JDM.HasFlags(Model.Flags, "AnonCommentAllowed")))
    {
        <a href="@Url.Action(Loc.Act("Comment").Ctrl("Feedback").Area("Wizard").Set(new
        {
            tgtID = JDM.Int32(Model.EntityID),
            tgtType = "catalogsupplier"
        }).Localized())">@T(Res.Name("Comment"))</a>
    }
}
@section Sidebar
{
    @if(JDM.HasFlags(Model.Flags, "RatingAllowed"))
    {
        <div class="box">
            <section>
            @{
                Html.RenderPartial("_Rating");
            }
            </section>
        </div>
    }
     @if(Model.FileGroup != null)
    {
        <div class="box">
            <header>
                <h3>@T(Res.Name("Attachments"))</h3>
            </header>
            <section>
            @{ 
                Html.RenderAction(Loc.Act("_Attachments").Ctrl("Media").NoArea().Set(new
                {
                    groupID = JDM.Int32(Model.FileGroup.EntityID)
                }).Localized()); 
            }
            </section>
        </div>
    }
    @{
        var addrs = Model.Addresses as IEnumerable<dynamic>;
        if(addrs.Any())
        {
            <div class="box">
                <header>
                    <h3>@T(Res.Name("Addresses"))</h3>
                </header>
                <section>
                @{
                    Html.RenderPartial("_Addresses", addrs);
                }
                </section>
            </div>
        }
    }
}
<div class="box @(JDM.HasFlags(Model.Flags, "Promoted") ? "promoted" : String.Empty)">
    <section>
        <table class="columned">
            <tbody>
                <tr>
                    <td>
                    @{
                        Html.RenderPartial("_Image");
                    }
                    </td>
                    <td style="width: 100%;">
                    @{
                        Html.RenderPartial("_ShortDescription");
                        Html.RenderPartial("_Attributes");
                    }
                    </td>
                </tr>
            </tbody>
        </table>
    </section>
    <section>
    @{
        Html.RenderPartial("_Description");
    }
    </section>
</div>
<div class="box">
    <header>
        <h3>@T(Res.Name("Items"))</h3>
    </header>
    <section>
    @{
        Html.RenderAction(Loc.Act("_Latest").Ctrl("Item").Set(new
        {
            supplierID = JDM.Int32(Model.EntityID)
        }).Localized());
    }
    </section>
    <footer>
        <nav>
            <a href="@Url.Action(Loc.Act("Index").Ctrl("Item").Area("Store").Set(new
            {
                supplierID = JDM.Int32(Model.EntityID)
            }).Localized())">@T(Res.Name("Store"))</a>
            <span class="separator">|</span>
            @{
                var cats = Model.Categories as IEnumerable<dynamic>;
                if(cats.Any())
                {
                    var tmp = new List<dynamic>();
                    foreach(var i in cats)
                    {
                        var t_cat = (i.Translations as IEnumerable<dynamic>)
                                .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                                    JDM.Int32(Svc.Localization.Language.EntityID));
                        tmp.Add(new
                        {
                            Entity = i,
                            Name = t_cat != null ? JDM.String(t_cat.Name) : JDM.String(i.EntityID),
                        });
                    }
                    var n = 0;
                    foreach(var j in tmp)
                    {
                        <a href="@Url.Action(Loc.Act("Index").Ctrl("Item").Set(new
                        {
                            supplierID = JDM.Int32(Model.EntityID),
                            categoryID = JDM.Int32(j.Entity.EntityID)
                        }).Localized())">@j.Name</a>
                        if(n < tmp.Count() - 1)
                        {
                            <span class="separator">,</span>
                        }
                        n++;
                    }
                    <span class="separator">|</span>
                }
            }
            <a href="@Url.Action(Loc.Act("Index").Ctrl("Item").Set(new
            {
                supplierID = JDM.Int32(Model.EntityID)
            }).Localized())">@T(Res.In("Common").Of("Vocab").Name("All"))</a>
        </nav>
    </footer>
</div>
@if(JDM.HasFlags(Model.Flags, "CommentAllowed"))
{
    <div class="box">
        <header>
            <h3>@T(Res.Name("Comments"), JDM.Int32(Model.CommentCount))</h3>
        </header>
        <section>
        @{
            Html.RenderAction(Loc.Act("_Comments").Set(new
            {
                id = JDM.Int32(Model.EntityID)
            }).Localized());
        }
        </section>
    </div>
}